package com.ydgk.jishuzhan.service.impl;

import com.ydgk.jishuzhan.beans.Comment;
import com.ydgk.jishuzhan.dao.CommentMapper;
import com.ydgk.jishuzhan.dao.UserMapper;
import com.ydgk.jishuzhan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Comment> findCommentsByBId(Integer id) {

        List<Comment> comments = commentMapper.findCommentsByBId(id);
        List<Comment> comments1=new ArrayList<>();
        for (Comment comment:comments){
            comment.getCommentInfo().setUser(userMapper.findUserById(comment.getUserId()));
            comments1.add(comment);
        }
        return comments1;
    }

    @Override
    public void insert(Comment comment) {
        commentMapper.insert(comment);
    }

    @Override
    public void insert2(Comment comment) {
        commentMapper.insert2(comment);
    }

    @Override
    public List<Comment> findCommentsByQId(Integer id) {
         List<Comment> comments = commentMapper.findCommentsByQId(id);
        List<Comment> comments1=new ArrayList<>();
        for (Comment comment:comments){
            comment.getCommentInfo().setUser(userMapper.findUserById(comment.getUserId()));
            comments1.add(comment);
        }
        return comments1;
    }

    @Override
    public Comment findLast() {
        return commentMapper.findLast();
    }
}
